using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using OpenNETCF.Windows.Forms.Calendar;

namespace OpenNETCF
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class WeekDemo : System.Windows.Forms.Form
	{
		private System.Windows.Forms.MainMenu mainMenu1;

		public WeekDemo()
		{
            using (new OpenNETCF.Windows.Forms.Cursor2())
            {
                InitializeComponent();
            }
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.mainMenu1 = new System.Windows.Forms.MainMenu();
            this.cal = new OpenNETCF.Windows.Forms.Calendar.WeekCalendar();
            this.SuspendLayout();
            // 
            // cal
            // 
            this.cal.ColorTimeOff = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(223)))), ((int)(((byte)(222)))));
            this.cal.ColorTimeOn = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(206)))));
            this.cal.DataProvider = null;
            this.cal.Date = new System.DateTime(2006, 5, 3, 15, 25, 16, 625);
            this.cal.DayBackColor = System.Drawing.Color.White;
            this.cal.DayForeColor = System.Drawing.Color.Black;
            this.cal.DetailsBackColor = System.Drawing.Color.White;
            this.cal.Dock = System.Windows.Forms.DockStyle.Fill;
            this.cal.EndHour = 17;
            this.cal.FirstDayOfWeek = System.DayOfWeek.Sunday;
            this.cal.Font = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Regular);
            this.cal.FontLabel = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Regular);
            this.cal.FontMonth = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.cal.ForeColor = System.Drawing.Color.Black;
            this.cal.GridColor = System.Drawing.Color.Black;
            this.cal.LabelBackColor = System.Drawing.Color.Navy;
            this.cal.LabelForeColor = System.Drawing.Color.White;
            this.cal.Location = new System.Drawing.Point(0, 0);
            this.cal.Name = "cal";
            this.cal.SaturdayForeColor = System.Drawing.Color.Blue;
            this.cal.SelectedDayBackColor = System.Drawing.SystemColors.ActiveCaption;
            this.cal.SelectedDayForeColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.cal.SelectedItem = null;
            this.cal.Size = new System.Drawing.Size(240, 268);
            this.cal.StartHour = 8;
            this.cal.SundayForeColor = System.Drawing.Color.Red;
            this.cal.TabIndex = 0;
            this.cal.WeekendForeColor = System.Drawing.Color.Red;
            // 
            // WeekDemo
            // 
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
            this.ClientSize = new System.Drawing.Size(240, 268);
            this.Controls.Add(this.cal);
            this.Menu = this.mainMenu1;
            this.MinimizeBox = false;
            this.Name = "WeekDemo";
            this.Text = "Week Calendar";
            this.Resize += new System.EventHandler(this.Form1_Resize);
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

		}
		#endregion

        private WeekCalendar cal;


        StaticCalendarDataProvider dataProvider;

		private void Form1_Load(object sender, System.EventArgs e)
		{
            using (new OpenNETCF.Windows.Forms.Cursor2())
            {
                dataProvider = new StaticCalendarDataProvider();
                cal.Bounds = ClientRectangle;
                cal.DrawLabel += new DrawLabelHandler(cal_DrawLabel);
                cal.GetLabel += new GetLabelHandler(cal_GetLabel);
                dataProvider.Add(new OpenNETCF.Windows.Forms.Calendar.CalendarItem(DateTime.Parse("12/12/05 2:00 PM"), TimeSpan.FromHours(4), null, "Bob's birthday party"));
                dataProvider.Add(new OpenNETCF.Windows.Forms.Calendar.CalendarItem(DateTime.Parse("12/12/05 3:00 PM"), TimeSpan.FromHours(1), null, "Bachelor party"));
                dataProvider.Add(new OpenNETCF.Windows.Forms.Calendar.CalendarItem(DateTime.Parse("12/12/05 4:00 PM"), TimeSpan.FromHours(1), null, "One night in Bangkok"));
                dataProvider.Add(new OpenNETCF.Windows.Forms.Calendar.CalendarItem(DateTime.Parse("12/12/05 6:00 PM"), TimeSpan.FromHours(36), null, "Presidential elections"));
                cal.DataProvider = dataProvider;
                cal.Date = DateTime.Parse("12/12/05");
                cal.SelectedItem = dataProvider[dataProvider.Count - 1];
                cal.ItemSelected += new EventHandler(cal_ItemSelected);
                cal.DetailsBackColor = Color.White;
                cal.LabelForeColor = Color.DarkGray;
                this.Controls.Add(cal);
                cal.BringToFront();
            }
		}

        void cal_ItemSelected(object sender, EventArgs e)
        {
            MessageBox.Show("Selected item: " + cal.SelectedItem.Text); ;
        }

		private string cal_GetLabel(DateTime date)
		{
			if ( date == DateTime.Now.Date )
				return "42";
			return "";
		}

		private void cal_DrawLabel(BaseCalendar sender, DateTime date, Rectangle rectCell, Graphics gxCell)
		{
			SolidBrush br = new SolidBrush(Color.Black);
			gxCell.DrawString(date.ToString("MM/dd"), sender.Font, br, rectCell.X + 2, rectCell.Y + 14);
			br.Dispose();
		}

		private void Form1_Resize(object sender, System.EventArgs e)
		{
			cal.Bounds = ClientRectangle;
		}
	}
}
